package classDAO;

import java.util.List;

import mappedClass.TypeTask;

import org.hibernate.Query;
import org.hibernate.Session;

import testhibernate.HibernateUtil;

public class TypeTaskDAO implements DAO {

	public List findAll() {
		Session s = HibernateUtil.getSessionFactory().openSession();
		List list = s.createQuery("FROM TypeTask tt").list();
		s.close();
		return list;
	}

	public Object getById(int id) {
		Session s = HibernateUtil.getSessionFactory().openSession();

		return (TypeTask) s.get(TypeTask.class, id);
	}

	public int getIdByName(String name) {
		Session s = HibernateUtil.getSessionFactory().openSession();

		Query q = s.createQuery(
				"SELECT id FROM TypeTask tt where tt.name= :name").setString(
				"name", name);
		int id = (Integer) q.uniqueResult();
		return id;
	}
}
